﻿using System;
using System.Web.UI.WebControls;
using AppCommon;
using Controller;


public partial class SubMedia : System.Web.UI.Page
{
    public static string _uniqueid;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            var parameter = Request.QueryString["UniqueId"];
            if (!String.IsNullOrEmpty(parameter))
            {
                _uniqueid = parameter;
                linkMedia.Text = "Media";
                linkMedia.NavigateUrl = "~/media";
                BindData(parameter);
            }
        }
    }

    public void BindData(string uniqueId)
    {
        var id = GetIdSubLoaidivu(uniqueId);
        FillGrid1(id);
        // FillGrid2(id);
    }

    /// <summary>
    /// Lay id cua loai dich vu
    /// </summary>
    /// <returns></returns>
    public int GetIdLoaiDiVu()
    {
        var controller = new VYC04Controller();
        var model = controller.GetByUniqueId(AppCommon.Common.ConvertToUnSign(Constants.CM_DICHVU));
        return model.Count > 0 ? model[0].Id : 0;
    }

    public int GetIdSubLoaidivu(string uniqueid)
    {
        var controller = new VYC05Controller();
        var model = controller.GetByUniqueId(uniqueid);
        if (model.Count > 0)
        {
            linkSubMedia.Text = model[0].Ten;
            litTitlePage.Text = "Media - " + model[0].Ten;
            return model[0].Id;
        }
        return 0;
    }

    public void FillGrid1(int idSubDichvu)
    {
        var controller = new VYC06Controller();
        var model = controller.GetBySubLoaiCmMoinhat(idSubDichvu, 1);
        gv.DataSource = model;
        gv.DataBind();
    }
    public void FillGrid2(int idSubDichvu)
    {
        var controller = new VYC06Controller();
        var model = controller.GetBySubLoaiCmNoibat(idSubDichvu, 1);
        // gvXemnhieu.DataSource = model;
        // gvXemnhieu.DataBind();
    }

    /// <summary>
    /// Event OnPageIndexChanging="gv_PageIndexChanging" on GridView
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void gv_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        gv.PageIndex = e.NewPageIndex;
        BindData(_uniqueid);
    }
}